<?php

declare(strict_types=1);

namespace Plugin\Attractions\Inspection\Model\Inspection_devices;

use Hyperf\Database\Model\Relations\BelongsTo;
use Hyperf\DbConnection\Model\Model;
use Plugin\Attractions\Inspection\Model\Inspection_device_types\InspectionDeviceTypes;
use Plugin\Attractions\Inspection\Model\Inspection_vendors\InspectionVendors;

/**
 * @property int $id ID
 * @property string $name 设备名称
 * @property string $model 设备型号
 * @property float $longitude 经度
 * @property float $latitude 纬度
 * @property float $altitude 海拔高度
 * @property int $type_id 设备类型ID
 * @property int $status 当前状态 1在线 2离线
 * @property int $vendor_id 供应商ID
 * @property int $service_id 服务商ID
 * @property string $device 关联设备
 * @property \Carbon\Carbon $created_at 
 * @property \Carbon\Carbon $updated_at 
 */
class InspectionDevices extends Model
{
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'inspection_devices';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'name', 'model', 'longitude', 'latitude', 'altitude', 'type_id', 'status', 'vendor_id', 'service_id', 'device', 'created_at', 'updated_at'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'longitude' => 'decimal:6', 'latitude' => 'decimal:6', 'altitude' => 'decimal:2', 'type_id' => 'integer', 'status' => 'integer', 'vendor_id' => 'integer', 'service_id' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];

    public function type(): BelongsTo
    {
        return $this->belongsTo(InspectionDeviceTypes::class, 'type_id', 'id');
    }

    public function vendor(): BelongsTo
    {
        return $this->belongsTo(InspectionVendors::class, 'vendor_id', 'id');
    }

    public function service(): BelongsTo
    {
        return $this->belongsTo(InspectionVendors::class, 'service_id', 'id');
    }
}
